#!/bin/awk -f
## select tiling(s) number from tilings.out
## Synopsis: cat TILING | poptil N1[,N2,N3...]
BEGIN{
  sel=ARGV[1];
  na=split(ARGV[1],a,",");
  if(na>1){
    sel=0;
    for(i=1;i<=na;i++){
      s[a[i]]++;
      if(a[i]>sel){sel=a[i]};
    }
  }
  ARGV[1]="-"; 
  ARGC=2;
}
FNR==1{
  nn=$1; mu=$2; nt=$3;
  print nn,mu,na"  # tilings via poptils";
}
FNR>1&&FNR<4{print} #basis
FNR==3{
  for(i=1;i<=sel;i++){
    pr=0; if(s[i]>0){pr=1;n++;t[n]=""};
    if(sel>nt){exit}
    for(j=1;j<=nn;j++){
      getline; 
      if(pr>0){
	t[n]=t[n]""$0"\n";
#	print $0;
      }
    }
  }
}
END{
  for(i=1;i<=n;i++){printf t[i]};
}
